home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / demos / OpenGL / stonehenge / Roundwall.c++ < prev    next >
C/C++ Source or Header  |  1996-11-11  |  3KB  |  97 lines

  1. /*
  2.  * (c) Copyright 1993, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software for
  6.  * any purpose and without fee is hereby granted, provided that the above
  7.  * copyright notice appear in all copies and that both the copyright notice
  8.  * and this permission notice appear in supporting documentation, and that
  9.  * the name of Silicon Graphics, Inc. not be used in advertising
  10.  * or publicity pertaining to distribution of the software without specific,
  11.  * written prior permission.
  12.  *
  13.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  14.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  15.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  16.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  17.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  18.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  19.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  20.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  21.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  22.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  23.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  24.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  25.  *
  26.  * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND
  27.  * Use, duplication, or disclosure by the Government is subject to
  28.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  29.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  30.  * clause at DFARS 252.227-7013 and/or in similar or successor
  31.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  32.  * Unpublished-- rights reserved under the copyright laws of the
  33.  * United States.  Contractor/manufacturer is Silicon Graphics,
  34.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  35.  *
  36.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  37.  */
  38. #include <GL/glu.h>
  39. #include <GL/glx.h>
  40.  
  41. #include <math.h>
  42.  
  43. #include "Roundwall.h"
  44.  
  45. Roundwall::Roundwall()
  46. {
  47.   height = 2;
  48.   radius = 20;
  49.   divisions = 20;
  50.   sint = cost = NULL;
  51. }
  52.  
  53. void Roundwall::draw()
  54. {
  55.   float texx = 0;
  56.   int i;
  57.   if (sint == NULL) compute_tables();
  58.   glBegin(GL_QUAD_STRIP);
  59.   for (i = 0; i <= divisions; i++, texx += 1.) {
  60.     glTexCoord2f(texx, 0);
  61.     glNormal3f(-cost[i], -sint[i], 0);
  62.     glVertex3f(radius * cost[i], radius * sint[i], 0);
  63.     glTexCoord2f(texx, 1);
  64.     glVertex3f(radius * cost[i], radius * sint[i], height);
  65.   }
  66.   glEnd();
  67. }
  68.  
  69. void Roundwall::set_divisions(int d)
  70. {
  71.   if (divisions != d) delete_tables();
  72.   divisions = d;
  73. }
  74.  
  75. void Roundwall::delete_tables()
  76. {
  77.   delete sint;
  78.   delete cost;
  79.   sint = cost = NULL;
  80. }
  81.  
  82. void Roundwall::compute_tables()
  83. {
  84.   int i;
  85.   float t, dt;
  86.  
  87.   delete_tables();
  88.   cost = new float[divisions + 1];
  89.   sint = new float[divisions + 1];
  90.  
  91.   dt = 2. * M_PI / divisions;
  92.   for (i = 0, t = 0.; i <= divisions; i++, t += dt) {
  93.     cost[i] = cos(t);
  94.     sint[i] = sin(t);
  95.   }
  96. }
  97.